Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry on failure support to JunitReporter #293

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

nandodelauni
Copy link
Contributor

@nandodelauni nandodelauni commented Jul 24, 2024

🎩 What is the goal?

Avoid false positives when retry on failure is enabled and there is one retry that passes. Right now the test is reported as both success and failure.

🔨 How is it being implemented?

By filtering out test failures if a test case passes and the previous components have the same classname and class which uniquely identifies a test.

Closes #290

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.01%. Comparing base (e7289f3) to head (f9bb063).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #293      +/-   ##
==========================================
+ Coverage   86.85%   87.01%   +0.15%     
==========================================
  Files          14       14              
  Lines        1651     1671      +20     
==========================================
+ Hits         1434     1454      +20     
  Misses        217      217              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +24 to +25
// reduce failing retrys, if any
components.removePreviousFailingTestsAfter(testCase)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about removing previous failed iterations. We can't guarantee that test iterations fail for the same reason, so consolidating them here would suppress potentially important information. Looking at the JUnit specification and conventions, I think the current logic is correct– iteration failures should be recorded individually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about JUnit but afaik there is no built-in support for the retry-on-failure mechanism so I don't think JUnit is opinionated.

It is acceptable to agree that if one of the retries succeeds, the output should not contain a failure from such a test.

However, I get your point if all the retry fails for different reasons, but should they be reported more than once if it is one test? Should we fail twice because the error is different even if there is just one test failing? or should we make some decisions and grab one?

Comment on lines 30 to +33
} else if TestCasePassedCaptureGroup.regex.match(string: line) {
guard let testCase = generatePassingTest(line: line) else { return }
// filter out failing retrys, if any
components.removePreviousFailingTestsAfter(testCase)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a developer enables the "Run tests repeatedly" option, and each iteration passes, this will only show as 1 success, right? I don't think that's the desired behavior, and I don't think the current proposed changes consider that scenario. It's not one covered by the existing unit tests, but it should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, pushed some changes, thanks!

Comment on lines 176 to 183
mutating func removePreviousFailingTestsAfter(_ testCase: TestCase) {
// base case, empty array or last is not the last passed test case
guard let previousTestCase = last?.testCase,
testCase.classname == previousTestCase.classname,
testCase.name == previousTestCase.name
else {
return
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name says removePreviousFailing, but the guard doesn't actually consider if the last test is a failing one. It'd need to check that testCase.failure is non-nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this is required for Run tests repeatedly

Makefile Outdated
Comment on lines 135 to 137
.PHONY: xcode
xcode:
open Package.swift
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Can you include this change in a new PR? It'd be nice to get this change merged while we decide the path forward on this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem!

Copy link
Owner

@cpisciotta cpisciotta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nandodelauni. Thank you for your PR and patience! I've left some comments regarding concerns I have about merging this change.

From what I can tell, the current implementation seems to match the JUnit specifications and conventions. That said, I don't use JUnit, so I'm not familiar with many of its nuances or how other tools implement similar logic.

Could you help me better understand how you decided on this approach? Are there any resources or specifications you referenced that indicate how to handle iterations and retry failures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Successful retry on failure attempts are reported as failure
2 participants